package org.jeecg.modules.business.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.common.util.oConvertUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.business.dto.BatchAgreementOrderSavaDto;
import org.jeecg.modules.business.entity.*;
import org.jeecg.modules.business.enums.*;
import org.jeecg.modules.business.service.IBusAgreementOrderFeeService;
import org.jeecg.modules.business.service.IBusCommodityRecordService;
import org.jeecg.modules.business.service.IBusCustomerService;
import org.jeecg.modules.business.vo.AgreementAccountVo;
import org.jeecg.modules.rooms.entity.CesGoods;
import org.jeecg.modules.rooms.service.CesGoodsServiceImpl;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 协议账单表
 * @Author: jeecg-boot
 * @Date:   2023-05-25
 * @Version: V1.0
 */
@Api(tags="协议账单表")
@RestController
@RequestMapping("/business/busAgreementOrderFee")
@Slf4j
public class BusAgreementOrderFeeController extends JeecgController<BusAgreementOrderFee, IBusAgreementOrderFeeService> {
	@Autowired
	private IBusAgreementOrderFeeService busAgreementOrderFeeService;
	 @Autowired
	 private IBusCommodityRecordService busCommodityRecordService;
	 @Resource
	 private CesGoodsServiceImpl goodsService;
	 @Resource
	 private IBusCustomerService customerService;

	/**
	 * 分页列表查询
	 *
	 * @param busAgreementOrderFee
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "协议账单表-分页列表查询")
	@ApiOperation(value="协议账单表-分页列表查询", notes="协议账单表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<BusAgreementOrderFee>> queryPageList(BusAgreementOrderFee busAgreementOrderFee,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									@RequestParam(name="startTime",required = true) String startTime,
									@RequestParam(name="endTime",required = true) String endTime,
								   HttpServletRequest req) {
		QueryWrapper<BusAgreementOrderFee> queryWrapper = QueryGenerator.initQueryWrapper(busAgreementOrderFee, req.getParameterMap());
		Page<BusAgreementOrderFee> page = new Page<BusAgreementOrderFee>(pageNo, pageSize);
		if (oConvertUtils.isNotEmpty(startTime) && oConvertUtils.isNotEmpty(endTime)){
			queryWrapper.between("created_time", startTime,endTime);
		}
		IPage<BusAgreementOrderFee> pageList = busAgreementOrderFeeService.page(page, queryWrapper);
		pageList.getRecords().forEach(item -> {
			//处理客人信息
			if (oConvertUtils.isEmpty(item.getOrderFeeId())) {
				item.setGuest("协议单位");
			} else {
				//根据关联的入住单找到客户信息
				BusCustomer customer = customerService.getCustomerByOrderId(item.getOrderFeeId());
				if (customer != null){
					item.setGuest(customer.getName());
				}
			}
		});
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param busAgreementOrderFee
	 * @return
	 */
	@AutoLog(value = "协议账单表-添加")
	@ApiOperation(value="协议账单表-添加", notes="协议账单表-添加")
	//@RequiresPermissions("business:bus_agreement_order_fee:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody BusAgreementOrderFee busAgreementOrderFee) {
		busAgreementOrderFeeService.save(busAgreementOrderFee);
		return Result.OK("添加成功！");
	}

	 /**
	  *   添加
	  *
	  * @param busAgreementOrderFee
	  * @return
	  */
	 @AutoLog(value = "协议账单表-入账")
	 @ApiOperation(value="协议账单表-入账", notes="协议账单表-入账")
	 //@RequiresPermissions("business:bus_agreement_order_fee:add")
	 @PostMapping(value = "/addEntry")
	 public Result<String> addEntry(@RequestBody BusAgreementOrderFee busAgreementOrderFee) {
		 LoginUser user = TokenUtils.getAuthUser();
		 busAgreementOrderFee.setCreateUserId(user.getId());
		 busAgreementOrderFee.setCreatedTime(new Date());
		 busAgreementOrderFee.setCreateUserId(user != null ?user.getId():"");
		 //生成订单号
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		 String _fix = "";
		 switch (busAgreementOrderFee.getType()){
			 case 1:
				 _fix = "S";
			 	break;
			 case 2:
				 _fix = "T";
				 break;
			 case 3:
				 _fix = "R";
				 break;
		 }
		 busAgreementOrderFee.setOrderNo(_fix+sdf.format(System.currentTimeMillis()));
		 busAgreementOrderFee.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
		 busAgreementOrderFee.setDelFlag(CommonConstant.DEL_FLAG_0);
		 busAgreementOrderFeeService.save(busAgreementOrderFee);
		 if (busAgreementOrderFee.getCommodityRecords() != null && busAgreementOrderFee.getCommodityRecords().size() > 0){
			 List<BusCommodityRecord> commodityRecords = busAgreementOrderFee.getCommodityRecords();
			 commodityRecords.forEach(item -> {
				 item.setStatus(ReturnGoodsStatusEnum.NOT_RETURNED.getKey());
				 item.setDelFlag(CommonConstant.DEL_FLAG_0);
				 item.setReturnNumber(BigDecimal.valueOf(0));
				 item.setAgreementOrderFeeId(busAgreementOrderFee.getId());
				 if(!oConvertUtils.isNotEmpty(item.getCategoryTwoId())){
					 CesGoods cesGoods = goodsService.getById(item.getGoodsId());
					 if (cesGoods != null){
					 	item.setCategoryTwoId(cesGoods.getGoodType());
					 }
				 }
			 });
			 busCommodityRecordService.saveBatch(commodityRecords);
		 }
		 return Result.OK("添加成功！");
	 }

	 /**
	  *   退货
	  *
	  * @param busAgreementOrderFee
	  * @return
	  */
	 @AutoLog(value = "协议账单表-退货")
	 @ApiOperation(value="协议账单表-退货", notes="协议账单表-退货")
	 //@RequiresPermissions("business:bus_agreement_order_fee:add")
	 @PostMapping(value = "/addReturn")
	 public Result<String> addReturn(@RequestBody BusAgreementOrderFee busAgreementOrderFee) {
	 	if (oConvertUtils.isNotEmpty(busAgreementOrderFee.getId())){
			BusAgreementOrderFee oldOrderFee = busAgreementOrderFeeService.getById(busAgreementOrderFee.getId());
			if (oldOrderFee == null){
				return Result.error("未找到对应数据");
			}
			BusAgreementOrderFee returnOrderFee = new BusAgreementOrderFee();
			LoginUser user = TokenUtils.getAuthUser();
			returnOrderFee.setCreateUserId(user.getId());
			returnOrderFee.setCreatedTime(new Date());
			returnOrderFee.setCreateUserId(user != null ?user.getId():"");
			//生成订单号
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
			String _fix = "R";
			returnOrderFee.setOrderNo(_fix+sdf.format(System.currentTimeMillis()));
			returnOrderFee.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
			returnOrderFee.setDelFlag(CommonConstant.DEL_FLAG_0);
			returnOrderFee.setCategoryId(oldOrderFee.getCategoryId());
			returnOrderFee.setAgreementUnitId(oldOrderFee.getAgreementUnitId());
			returnOrderFee.setPayPrice(busAgreementOrderFee.getPayPrice());
			returnOrderFee.setRemarks(busAgreementOrderFee.getRemarks());
			returnOrderFee.setType(busAgreementOrderFee.getType());

			busAgreementOrderFeeService.save(returnOrderFee);

			LambdaQueryWrapper<BusCommodityRecord> querCommodity = new LambdaQueryWrapper<BusCommodityRecord>();
			querCommodity.eq(BusCommodityRecord::getAgreementOrderFeeId, busAgreementOrderFee.getId());
			List<BusCommodityRecord> oldList = busCommodityRecordService.list(querCommodity);
			if (oldList != null && oldList.size() > 0){
				if (busAgreementOrderFee.getCommodityRecords() != null && busAgreementOrderFee.getCommodityRecords().size() > 0){
					List<BusCommodityRecord> commodityRecords = busAgreementOrderFee.getCommodityRecords();
//					oldList.forEach(item -> {
//
//					});
					for(BusCommodityRecord item:oldList){
						for(BusCommodityRecord record:commodityRecords){
							if (record.getId().equals(item.getId())){
								//退貨
								item.setReturnNumber(record.getReturnNumber());
							}
						}
					}
					busCommodityRecordService.updateBatchById(oldList);
				}
			}
			return Result.OK("退货成功！");
		}else{
			return Result.error("未找到对应数据");
		}
	 }

	 /**
	  *  批量结算
	  *
	  * @param batchAgreementOrderSavaDto
	  * @return
	  */
	 @AutoLog(value = "协议账单表-批量结算")
	 @ApiOperation(value="协议账单表-批量结算", notes="协议账单表-批量结算")
	 @PostMapping(value = "/updateStatusBatch")
	 public Result<String> updateStatusBatch(@RequestBody BatchAgreementOrderSavaDto batchAgreementOrderSavaDto) {
		 if (batchAgreementOrderSavaDto == null) {
			 return Result.error("参数错误");
		 }
		 BusAgreementOrderFee busAgreementOrderFee = batchAgreementOrderSavaDto.getBusAgreementOrderFee();
		 LoginUser user = TokenUtils.getAuthUser();
		 busAgreementOrderFee.setCreateUserId(user.getId());
		 busAgreementOrderFee.setCreatedTime(new Date());
		 busAgreementOrderFee.setCreateUserId(user != null ? user.getId() : "");
		 //生成订单号
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		 String _fix = "R";
		 busAgreementOrderFee.setOrderNo(_fix + sdf.format(System.currentTimeMillis()));
		 busAgreementOrderFee.setStatus(AgreementOrderStatusEnum.SETTLEMENT.getKey());
		 busAgreementOrderFee.setDelFlag(CommonConstant.DEL_FLAG_0);
		 busAgreementOrderFeeService.save(busAgreementOrderFee);

		 QueryWrapper<BusAgreementOrderFee> querOrderFee = new QueryWrapper<BusAgreementOrderFee>();
		 List<String> selectionList = Arrays.asList(batchAgreementOrderSavaDto.getOrderIds().split(","));
		 querOrderFee.in("id", selectionList);
		 List<BusAgreementOrderFee> orderFeeList = busAgreementOrderFeeService.list(querOrderFee);
		 if (orderFeeList != null && orderFeeList.size() > 0) {
			 orderFeeList.forEach(item -> {
				 item.setStatus(AgreementOrderStatusEnum.SETTLEMENT.getKey());
				 item.setSettlementOrderFeeId(busAgreementOrderFee.getId());
			 });
			 this.busAgreementOrderFeeService.updateBatchById(orderFeeList);
		 }
		 return Result.OK("结算成功!");
	 }

	 /**
	  *  撤销结算
	  *
	  * @param busAgreementOrderFee
	  * @return
	  */
	 @AutoLog(value = "协议账单表-撤销结算")
	 @ApiOperation(value="协议账单表-撤销结算", notes="协议账单表-撤销结算")
	 @RequestMapping(value = "/revoke", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> revoke(@RequestBody BusAgreementOrderFee busAgreementOrderFee) {
		 BusAgreementOrderFee oldOrderFee = busAgreementOrderFeeService.getById(busAgreementOrderFee.getId());
		 LambdaUpdateWrapper<BusAgreementOrderFee> updateWrapper = new UpdateWrapper().lambda();
		 if (oldOrderFee != null) {
		 	if (oldOrderFee.getType() != null && oldOrderFee.getType().equals(5)){
//				QueryWrapper<BusAgreementOrderFee> querOrderFee = new QueryWrapper<BusAgreementOrderFee>();
//				querOrderFee.eq("settlement_order_fee_id", oldOrderFee.getId());
//				List<BusAgreementOrderFee> orderFeeList = busAgreementOrderFeeService.list(querOrderFee);
//				if (orderFeeList != null && orderFeeList.size() > 0) {
////					for(BusAgreementOrderFee item : orderFeeList){
////						item.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
////						item.setSettlementOrderFeeId("");
////					}
//					orderFeeList.forEach(item -> {
//						item.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
//						item.setSettlementOrderFeeId("");
//					});
//					busAgreementOrderFeeService.updateBatchById(orderFeeList);
//				}
				updateWrapper = new UpdateWrapper().lambda();
				updateWrapper.eq(BusAgreementOrderFee::getSettlementOrderFeeId, oldOrderFee.getId());
				updateWrapper.set(BusAgreementOrderFee::getStatus, AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
				updateWrapper.set(BusAgreementOrderFee::getSettlementOrderFeeId, "");

				//关联结算记录更改为未结算
				busAgreementOrderFeeService.update(updateWrapper);
				//结算记录删除
				busAgreementOrderFeeService.removeById(oldOrderFee);
			}else{
		 		if (oConvertUtils.isNotEmpty(oldOrderFee.getSettlementOrderFeeId())){
					BusAgreementOrderFee settlementModel = busAgreementOrderFeeService.getById(oldOrderFee.getSettlementOrderFeeId());
					if (settlementModel != null){

						updateWrapper = new UpdateWrapper().lambda();
						updateWrapper.eq(BusAgreementOrderFee::getSettlementOrderFeeId, settlementModel.getId());
						updateWrapper.set(BusAgreementOrderFee::getStatus, AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
						updateWrapper.set(BusAgreementOrderFee::getSettlementOrderFeeId, "");

						//关联结算记录更改为未结算
						busAgreementOrderFeeService.update(updateWrapper);
						//结算记录删除
						busAgreementOrderFeeService.removeById(settlementModel);

//						QueryWrapper<BusAgreementOrderFee> querOrderFee = new QueryWrapper<BusAgreementOrderFee>();
//						querOrderFee.eq("settlement_order_fee_id", settlementModel.getId());
//						List<BusAgreementOrderFee> orderFeeList = busAgreementOrderFeeService.list(querOrderFee);
//						if (orderFeeList != null && orderFeeList.size() > 0) {
//							for(BusAgreementOrderFee item : orderFeeList){
//								item.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
//								item.setSettlementOrderFeeId("");
//							}
////							orderFeeList.forEach(item -> {
////								item.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
////								item.setSettlementOrderFeeId("");
////								updateOrderFeeList.add(item);
////							});
//							busAgreementOrderFeeService.updateBatchById(orderFeeList);
//						}
					}
				}
			}
		 }
		 return Result.OK("撤销成功!");
	 }

	 /**
	  *  批量转账
	  *
	  * @param batchAgreementOrderSavaDto
	  * @return
	  */
	 @AutoLog(value = "协议账单表-批量转账")
	 @ApiOperation(value="协议账单表-批量转账", notes="协议账单表-批量转账")
	 @PostMapping(value = "/transferBatch")
	 public Result<String> transferBatch(@RequestBody BatchAgreementOrderSavaDto batchAgreementOrderSavaDto) {
		 if (batchAgreementOrderSavaDto == null) {
			 return Result.error("参数错误");
		 }

		 QueryWrapper<BusAgreementOrderFee> querOrderFee = new QueryWrapper<BusAgreementOrderFee>();
		 List<String> selectionList = Arrays.asList(batchAgreementOrderSavaDto.getOrderIds().split(","));
		 querOrderFee.in("id", selectionList);
		 List<BusAgreementOrderFee> orderFeeList = busAgreementOrderFeeService.list(querOrderFee);
		 if (orderFeeList != null && orderFeeList.size() > 0) {
			 orderFeeList.forEach(item -> {
				 item.setAgreementUnitId(batchAgreementOrderSavaDto.getAgreementUnitId());
			 });
			 this.busAgreementOrderFeeService.updateBatchById(orderFeeList);
		 }
		 return Result.OK("结算成功!");
	 }

	 /**
	  *   添加
	  *
	  * @param busAgreementOrderFee
	  * @return
	  */
	 @AutoLog(value = "协议账单表-冲账")
	 @ApiOperation(value="协议账单表-冲账", notes="协议账单表-冲账")
	 @PostMapping(value = "/reverseEntry")
	 public Result<String>  reverseEntry(@RequestBody BusAgreementOrderFee busAgreementOrderFee) {
		 LoginUser user = TokenUtils.getAuthUser();
		 busAgreementOrderFee.setCreateUserId(user.getId());
		 busAgreementOrderFee.setCreatedTime(new Date());
		 busAgreementOrderFee.setCreateUserId(user != null ?user.getId():"");
		 busAgreementOrderFee.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
		 busAgreementOrderFee.setDelFlag(CommonConstant.DEL_FLAG_0);
		 busAgreementOrderFeeService.save(busAgreementOrderFee);

		 return Result.OK("冲账成功！");
	 }


	 /**
	  * 获取协议单位消费、收款信息
	  *
	  * @param agreementUnitId
	  * @return
	  */
	 //@AutoLog(value = "协议账单表-消费、收款信息")
	 @ApiOperation(value="协议账单表-消费、收款信息", notes="协议账单表-消费、收款信息")
	 @GetMapping(value = "/queryAgreementAccount")
	 public Result<AgreementAccountVo> queryAgreementAccount(
			 @RequestParam(name="startTime",required = true) String startTime,
			 @RequestParam(name="endTime",required = true) String endTime,
			 @RequestParam(name="agreementUnitId",required=true) String agreementUnitId) {
		 AgreementAccountVo agreementAccountVo = new AgreementAccountVo();
		 agreementAccountVo.setConsume(BigDecimal.valueOf(0));
		 agreementAccountVo.setPayment(BigDecimal.valueOf(0));
		 String types = AgreementOrderTypeEnum.PAYMENT.getKey()+","+AgreementOrderTypeEnum.REFUND.getKey();
		 List<String> typeList = Arrays.asList(types.split(","));

		 QueryWrapper<BusAgreementOrderFee> querOrderFee = new QueryWrapper<BusAgreementOrderFee>();
		 querOrderFee.eq("agreement_unit_id", agreementUnitId);
		 querOrderFee.eq("status", AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
		 querOrderFee.notIn("type",typeList);
		 if (oConvertUtils.isNotEmpty(startTime) && oConvertUtils.isNotEmpty(endTime)){
			 querOrderFee.between("created_time", startTime,endTime);
		 }
		 List<BusAgreementOrderFee> orderFeeList = busAgreementOrderFeeService.list(querOrderFee);

		 BigDecimal _consume = new BigDecimal("0.00");
		 if (orderFeeList != null && orderFeeList.size() > 0){
		 	for (BusAgreementOrderFee item : orderFeeList){
				BigDecimal _price = new BigDecimal(item.getPayPrice().toString());
				_consume = _consume.add(_price);

			}
			 agreementAccountVo.setConsume(_consume);

		 }

		 QueryWrapper<BusAgreementOrderFee> querOrderFee1 = new QueryWrapper<BusAgreementOrderFee>();
		 querOrderFee1.eq("agreement_unit_id", agreementUnitId);
		 querOrderFee1.eq("status", AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
		 querOrderFee1.in("type", typeList);
		 if (oConvertUtils.isNotEmpty(startTime) && oConvertUtils.isNotEmpty(endTime)){
			 querOrderFee1.between("created_time", startTime,endTime);
		 }
		 List<BusAgreementOrderFee> orderFeeList1 = busAgreementOrderFeeService.list(querOrderFee1);

		 BigDecimal _payment = new BigDecimal("0.00");
		 if (orderFeeList1 != null && orderFeeList1.size() > 0){
			 for (BusAgreementOrderFee item : orderFeeList1){
				 BigDecimal _price = new BigDecimal(item.getPayPrice().toString());
				 _payment = _payment.add(_price);

			 }
			 agreementAccountVo.setPayment(_payment);
		 }
		 return Result.OK(agreementAccountVo);
	 }

	 /**
	  *  编辑备注
	  *
	  * @param busAgreementOrderFee
	  * @return
	  */
	 @AutoLog(value = "协议账单表-编辑备注")
	 @ApiOperation(value="协议账单表-编辑备注", notes="协议账单表-编辑备注")
	 //@RequiresPermissions("business:bus_agreement_order_fee:edit")
	 @RequestMapping(value = "/editRemarks", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> editRemarks(@RequestBody BusAgreementOrderFee busAgreementOrderFee) {
		 BusAgreementOrderFee editModel = busAgreementOrderFeeService.getById(busAgreementOrderFee.getId());
		 if (editModel != null) {
			 editModel.setRemarks(busAgreementOrderFee.getRemarks());
			 busAgreementOrderFeeService.updateById(busAgreementOrderFee);
			 return Result.OK("编辑成功!");
		 } else {
			 return Result.error("参数错误");
		 }
	 }

	/**
	 *  编辑
	 *
	 * @param busAgreementOrderFee
	 * @return
	 */
	@AutoLog(value = "协议账单表-编辑")
	@ApiOperation(value="协议账单表-编辑", notes="协议账单表-编辑")
	//@RequiresPermissions("business:bus_agreement_order_fee:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody BusAgreementOrderFee busAgreementOrderFee) {
		busAgreementOrderFeeService.updateById(busAgreementOrderFee);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "协议账单表-通过id删除")
	@ApiOperation(value="协议账单表-通过id删除", notes="协议账单表-通过id删除")
	//@RequiresPermissions("business:bus_agreement_order_fee:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		busAgreementOrderFeeService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "协议账单表-批量删除")
	@ApiOperation(value="协议账单表-批量删除", notes="协议账单表-批量删除")
	//@RequiresPermissions("business:bus_agreement_order_fee:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.busAgreementOrderFeeService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "协议账单表-通过id查询")
	@ApiOperation(value="协议账单表-通过id查询", notes="协议账单表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<BusAgreementOrderFee> queryById(@RequestParam(name="id",required=true) String id) {
		BusAgreementOrderFee busAgreementOrderFee = busAgreementOrderFeeService.getById(id);
		if(busAgreementOrderFee==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(busAgreementOrderFee);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param busAgreementOrderFee
    */
    //@RequiresPermissions("business:bus_agreement_order_fee:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, BusAgreementOrderFee busAgreementOrderFee) {
        return super.exportXls(request, busAgreementOrderFee, BusAgreementOrderFee.class, "协议账单表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("business:bus_agreement_order_fee:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, BusAgreementOrderFee.class);
    }

}
